﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using MReviewerClient.MReviewerSvc;

namespace MReviewerClient.Providers
{
    public class MReviewerService
    {
        /// <summary>
        /// The instance of service
        /// </summary>
        private static SvcMReviewerClient instance;

        /// <summary>
        /// The lock object for synchronization
        /// </summary>
        private static object syncLock = new object();

        /// <summary>
        /// The name of endpoint address
        /// </summary>
        private const string ENDPOINT_ADDRESS_NAME = "BasicHttpBinding_ISvcMReviewer";

        /// <summary>
        /// The default endpoint address
        /// </summary>
        private const string DEFAULT_ENDPOINT_ADDRESS = "http://localhost:18659/SvcMReviewer.svc";

        /// <summary>
        /// Th Singleton instance
        /// </summary>
        public static SvcMReviewerClient Instance
        {
            get
            {
                lock (syncLock)
                {
                    if (instance == null)
                    {
                        try
                        {
                            var serviceURL = ServiceInfoProvider.Instance.ServiceURL;
                            instance = new MReviewerSvc.SvcMReviewerClient(ENDPOINT_ADDRESS_NAME,
                                new EndpointAddress(serviceURL == string.Empty ? DEFAULT_ENDPOINT_ADDRESS : serviceURL));
                        }
                        catch(Exception ex) { }
                    }
                    return instance;
                }
            }
        }
    }
}
